<?php
/**
 * Menu
 *-------------------------
 *
 * Deal with menu display, selected status. Top menu - sub menu 
 *
 * PHP versions 5
 *
 * LICENSE: This source file is from Smarter Ver4.0, which is a comprehensive shopping engine
 * that helps consumers to make smarter buying decisions online. We empower consumers to compare
 * the attributes of over one million products in the computer and consumer electronics categories
 * and to read user product reviews in order to make informed purchase decisions. Consumers can then
 * research the latest promotional and pricing information on products listed at a wide selection of
 * online merchants, and read user reviews on those merchants.
 * The copyrights is reserved by http://www.mezimedia.com.
 * Copyright (c) 2005, Mezimedia. All rights reserved.
 *
 * @author     kevin cheng <kevin_cheng@mezimedia.com>
 * @copyright  (C) 2004-2008 Mezimedia.com
 * @license    http://www.mezimedia.com  PHP License 5.2
 * @version    CVS: $Id: UserController.php
 * @link       http://pms.mezimedia.com/
 * @deprecated File deprecated in Release 1.0
 */
 
class Menu {
	
	/*
	 * Define the default Top menu
	 * */
	private $menu = array (
		'Home' => array (
			'key' => 'user',
			'url' => '/user/',
			'selected' => false,
			'title' => 'User default page',			
		),
		'Tickets' => array (
			'key' => 'ticket',
			'url' => '/ticket/',
			'selected' => false,
			'title' => 'Tickets from requirement'
		),
		'Tasks' => array (
			'key' => 'task',
			'url' => '/task/',
			'selected' => false,
			'title' => 'Task maintaince, status tracking '
		),		
		'Reports' => array (
			'key' => 'report',
			'url' => '/report/calendar',
			'selected' => false,
			'title' => 'Reports for task, team, user'
		),
		'Wizards' => array (
			'key' => 'wizard',
			'url' => '/wizard/',
			'selected' => false,
			'title' => 'Wizards to configure the system, team config, score config, user config'
		)
	);

	/*
	 * @desc Called by each controller, set the sub level menus
	 * @param $controller key for the menu match
	 * @param $submenu sub menu info of this controller
	 * */
	public function renderMenu($controller='', $action='', $subMenu = array ()) {
		$menuReturn = array();
		$menuTree = $this->menu;
		if($controller !='' && count($subMenu) >0){			
			foreach($menuTree as $label=>$menuItem){
				if($menuItem['key'] == $controller){
					$menuTree[$label]['selected'] = true;					
					//set the submenu selected
					if($action == ''){
						$subMenu[0]['selected'] = true;
					}else{
						foreach($subMenu as $subLabel=>$subMenuItem){
							if($subMenuItem['key'] == $action){
								$subMenu[$subLabel]['selected'] = true;
							}
						}
						//todo sub menu not matched
					}
					//$menuTree[$label]['subMenu'] = $subMenu;
					break;
				}
			}
		}
		//return $menuTree;
		
		$menuReturn['level1'] = $menuTree;
		$menuReturn['level2'] = $subMenu;		
		return $menuReturn;
	}
}
?>
